package top.lbqaq.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "Filter4", urlPatterns = "/4-3.jsp")
public class Filter4 implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        Object username = req.getSession().getAttribute("username");
        if (username == null) {
            req.setAttribute("msg", "您没有登陆");
            req.getRequestDispatcher("/4-1.jsp").forward(req, resp);
        } else {
            chain.doFilter(request, response);
        }
    }
}
